//
//  MMRuleView.m
//  ZZLC
//
//  Created by 杨春至 on 2017/12/13.
//  Copyright © 2017年 ZhongZeng. All rights reserved.
//

#import "MMRuleView.h"

@interface ComBineView : UIView
@property (nonatomic,strong) UILabel *titleLb;

@property (nonatomic,strong) UILabel *desLb;

@property (nonatomic,strong) UIImageView *circleView;

- (void)loadData:(NSString *)titleStr DesStr:(NSString *)desStr;
@end

@implementation ComBineView
- (instancetype)init{
    if ([super init]) {
        [self configUI];
    }
    return self;
}
- (void)configUI{
    [self addSubview:self.titleLb];
    [self addSubview:self.desLb];
    [self addSubview:self.circleView];
}
- (void)loadData:(NSString *)titleStr DesStr:(NSString *)desStr{
    self.titleLb.text = titleStr;
    self.desLb.text = desStr;
}
- (void)layoutSubviews{
    [_titleLb mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.equalTo(self);
        make.top.equalTo(self);
        make.width.equalTo(self);
        make.height.equalTo(@13);
    }];
    [_desLb mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.equalTo(self);
        make.bottom.equalTo(self);
        make.width.equalTo(self);
        make.height.equalTo(@13);
    }];
    [_circleView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.center.equalTo(self);
        make.size.mas_equalTo(CGSizeMake(17, 17));
    }];
}
- (UILabel *)titleLb{
    if (!_titleLb) {
        _titleLb = [UILabel new];
        _titleLb.textAlignment = NSTextAlignmentCenter;
        _titleLb.font = [UIFont systemFontOfSize:13];
    }
    return _titleLb;
}
- (UILabel *)desLb{
    if (!_desLb) {
        _desLb = [UILabel new];
        _desLb.textAlignment = NSTextAlignmentCenter;
        _desLb.font = [UIFont systemFontOfSize:12];
    }
    return _desLb;
}
- (UIImageView *)circleView{
    if (!_circleView) {
        _circleView = [UIImageView new];
        _circleView.contentMode = UIViewContentModeCenter;
//        _circleView.backgroundColor = [UIColor redColor];
        _circleView.image = UIImageMake(@"pgicon");
    }
    return _circleView;
}
@end


@interface MMRuleView ()

@property (nonatomic,strong) UILabel *titleLb;

@property (nonatomic,strong) UIView *lineView;

@property (nonatomic,strong) ComBineView *investView;

@property (nonatomic,strong) ComBineView *investbenefit;

@property (nonatomic,strong) ComBineView *investEndtime;

@property (nonatomic,strong) UILabel *infoLb;

@property (nonatomic,strong) UIView *lineView_2;

@property (nonatomic,strong) UIView *lineView_3;
@end

@implementation MMRuleView

- (instancetype)init{
    if ([super init]) {
        [self configUI];
    }
    return self;
}
- (void)setModel:(ProDetailModel *)model{
    _model = model;
    _investView.desLb.text = _model.nowDate;

    
    NSDateFormatter* formatter = [[NSDateFormatter alloc] init];
    [formatter setDateStyle:NSDateFormatterMediumStyle];
    [formatter setTimeStyle:NSDateFormatterShortStyle];
    [formatter setDateFormat:@"yyyy.MM.dd"];
    NSDate *date = [formatter dateFromString:_model.nowDate];
//    NSInteger timeSp = [[NSNumber numberWithDouble:[date timeIntervalSince1970]] integerValue];
    NSDate *nextDay = [NSDate dateWithTimeInterval:24*60*60 sinceDate:date];
//    NSLog(@"date1:%@",date);
    NSString *nextDatStr = [formatter stringFromDate:nextDay];
    NSDate *endDay = [NSDate dateWithTimeInterval:24*60*60*([_model.lcqx integerValue]) sinceDate:date];
    //    NSLog(@"date1:%@",date);
    NSString *endDatStr = [formatter stringFromDate:endDay];
    
    _investbenefit.desLb.text = nextDatStr;
    _investEndtime.desLb.text = endDatStr;
    
}
- (void)configUI{
    [self addSubview:self.titleLb];
    [self addSubview:self.lineView_2];
    [self addSubview:self.lineView_3];
    [self addSubview:self.investView];
    [self addSubview:self.investbenefit];
    [self addSubview:self.investEndtime];
    [self addSubview:self.lineView];
    [self addSubview:self.infoLb];
}
- (void)layoutSubviews{
    CGFloat gap = 15;
    CGFloat gap2 = 10;
    [_titleLb mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(@(gap));
        make.top.equalTo(@0);
        make.height.equalTo(@45);
        make.width.equalTo(self);
    }];
    [_investView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.mas_left).offset(gap);
        make.top.equalTo(_titleLb.mas_bottom).offset(gap);
        make.size.mas_equalTo(CGSizeMake(70, 70));
    }];
    [_investbenefit mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.equalTo(self);
        make.top.equalTo(_investView);
        make.size.mas_equalTo(CGSizeMake(70, 70));
    }];
    [_investEndtime mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(self.mas_right).offset(-gap);
        make.top.equalTo(_investView);
        make.size.mas_equalTo(CGSizeMake(70, 70));
    }];
    [_lineView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(self);
        make.top.equalTo(_titleLb.mas_bottom);
        make.height.equalTo(@(0.4));
        make.width.equalTo(self);
    }];
    [_infoLb mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.equalTo(self);
        make.top.equalTo(_investView.mas_bottom).offset(gap);
        make.height.equalTo(@18);
    }];
    [_lineView_2 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(_investView.circleView.mas_right).offset(gap2);
        make.right.equalTo(_investbenefit.circleView.mas_left).offset(-gap2);
        make.height.equalTo(@2);
        make.centerY.equalTo(_investView.circleView.mas_centerY);
    }];
    [_lineView_3 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(_investbenefit.circleView.mas_right).offset(gap2);
        make.right.equalTo(_investEndtime.circleView.mas_left).offset(-gap2);
        make.height.equalTo(@2);
        make.centerY.equalTo(_investView.circleView.mas_centerY);
    }];
}
- (UILabel *)titleLb{
    if (!_titleLb) {
        _titleLb = [[UILabel alloc]init];
        _titleLb.text = @"投资规则";
        _titleLb.font = [UIFont systemFontOfSize:15];
    }
    return _titleLb;
}
- (ComBineView *)investView{
    if (!_investView) {
        _investView = [[ComBineView alloc]init];
        [_investView loadData:@"现在投资" DesStr:@"2017/12/08"];
    }
    return _investView;
}
- (ComBineView *)investbenefit{
    if (!_investbenefit) {
        _investbenefit = [[ComBineView alloc]init];
         [_investbenefit loadData:@"产生收益" DesStr:@"2017/12/08"];
    }
    return _investbenefit;
}
- (ComBineView *)investEndtime{
    if (!_investEndtime) {
        _investEndtime = [[ComBineView alloc]init];
         [_investEndtime loadData:@"本期到期" DesStr:@"2017/12/08"];
    }
    return _investEndtime;
}
- (UIView *)lineView{
    if (!_lineView) {
        _lineView = [UIView new];
        _lineView.backgroundColor = [UIColor grayColor];
    }
    return _lineView;
}
- (UILabel *)infoLb{
    if (!_infoLb) {
        _infoLb = [UILabel new];
        _infoLb.backgroundColor = RGBCOLOR(241, 241, 241);
        _infoLb.text = @"  产品到期后本金和收益将在次日回款至您的账号余额。暂不支持提前赎回  ";
        _infoLb.font = [UIFont systemFontOfSize:9];
    }
    return _infoLb;
}
- (UIView *)lineView_2{
    if (!_lineView_2) {
        _lineView_2 = [UIView new];
        _lineView_2.backgroundColor = [UIColor qmui_colorWithHexString:@"#FFCF3E"];
    }
    return _lineView_2;
}
- (UIView *)lineView_3{
    if (!_lineView_3) {
        _lineView_3 = [UIView new];
        _lineView_3.backgroundColor = [UIColor qmui_colorWithHexString:@"#FFCF3E"];
    }
    return _lineView_3;
}
@end
